home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas2c.zip / SAVEREG.H < prev    next >
Text File  |  1993-01-04  |  2KB  |  43 lines

  1. /*
  2.  
  3.     SAVEREG.H
  4.  
  5.     The Turbo C compiler produces its best code when it is allowed to use
  6.     SI and DI as general registers. When Pascal is used to call a C function,
  7.     this works, because C functions that use SI and DI save and restore the
  8.     register values appropriately. If the C function calls a Pascal routine,
  9.     the Pascal routine is at liberty to destroy the values contained in SI
  10.     and DI. Turbo C provides an option (-r-) to support this, at the cost
  11.     of worsening code generation. The two macros in this file also solve the
  12.     problem, in a more efficient way. Every call from C to Pascal is to
  13.     be wrapped in a save_registers/restore_registers pair:
  14.  
  15.         save_registers;
  16.         PASCAL_PROCEDURE();
  17.         restore_registers;
  18.  
  19.     save_registers saves the contents of SI and DI before the call, 
  20.     restore_registers restores the contents of SI and DI after the call.
  21.  
  22.     The PASCAL program must make a POINTER called __rsp available globally,
  23.     and must point it to an area to be used as a save stack. 2 words are
  24.     used on this stack every time save_registers is used.
  25.  
  26.         var
  27.             __rsp : Pointer;
  28.             SiDiStack : array [0..10] of Word;
  29.         ...
  30.         begin
  31.         __rsp := @SiDiStack[0];
  32.         ...
  33.         end.
  34.  
  35.     save_registers and restore_registers are implemented as macros for
  36.     efficiency.
  37.  
  38.  */
  39.  
  40. #define save_registers {IMPORT WORD FAR *_rsp; *_rsp++ = _SI; *_rsp++ = _DI;}
  41. #define restore_registers {IMPORT WORD FAR *_rsp; _DI = *--_rsp; _SI = *--_rsp;}
  42.  
  43.